import { defineStore } from "pinia";

export const userDemo = defineStore(
  "demo",
  () => {
    let todos = ref([
      { id: 1, title: "吃饭" },
      { id: 2, title: "睡觉" },
      { id: 3, title: "打豆豆" },
    ]);

    let count = ref(0);

    let doubleCount = computed(() => count.value * 2);

    function increment() {
      return count.value++;
    }

    let age = ref(18);

    return {
      todos,

      count,
      doubleCount,
      increment,

      age,
    };
  },
  {
    persist: {
      enabled: true,
      strategies: [
        {
          storage: localStorage,
          // 指定存储的 key
          key: "my_todos",
          // 指定需要持久化的数据
          paths: ["todos", "count"],
        },
        {
          storage: sessionStorage,
          key: "my_todos",
          paths: ["age"],
        },
      ],
    },
  }
);
